from rest_framework.views import APIView
from rest_framework.response import Response
from dhm.models.Warehousing_System.administrator.administrator import Administrator
from django.contrib.auth.models import User

class GetUserView(APIView):
    def get(self, request):
        administrators = Administrator.objects.all()
        users = []
        for administrator in administrators:
            users.append({
                'id': administrator.id,
                'username': administrator.username,
                'phone_number': administrator.phone_number,
                'professional_title': administrator.professional_title,
                'creation_time': administrator.creation_time,
                'update_time': administrator.update_time,
                'verification_code': administrator.verification_code,
            })
        return Response(users)

    def delete(self, request):
        user_id = int(request.POST.get('user_id', 1))
        Administrator.objects.filter(id = user_id).delete()
        return Response({
            'result': "success",
        })
